
//取非行间样式

function getStyle(obj, name){
    if(obj.currentStyle)
    {
        return obj.currentStyle[name];
    }
    else
    {
        return getComputedStyle(obj,null)[name];
    }
}


//运动框架    参数写法startMove(oDiv, {width:  201, 0.15, height: 300,opacity: 100}，function(){}）
//第二个参数一般取0到1之间的数字，值越大速度越快

function startMove(obj, sp, json, fnEnd)
{
    clearInterval(obj.timer);
    obj.timer=setInterval(function () {
        for(var attr in json)
        {

            var bStop=true;
            var cur=0;
            if(attr=='opacity')
            {
                cur=Math.round(parseFloat(getStyle(obj,attr))*100);
            }
            else
            {
                cur=parseInt(getStyle(obj, attr));
            }

            var speed=(json[attr]-cur)*sp;
            speed=speed>0?Math.ceil(speed):Math.floor(speed);


            if(attr=='opacity')
            {
                obj.style.filter='alpha(opacity:'+(cur+speed)+')';
                obj.style.opacity=(cur+speed)/100;
            }
            else
            {
                obj.style[attr]=cur+speed+'px';
            }

        }

        if(cur!=json[attr])
            bStop=false;

        if (bStop)
        {
            clearInterval(obj.timer);
            if(fnEnd) fnEnd();
        }
    }, 30);
}





//通过class命选对象数组   参数写法var oBtnPrev=getByClass(oDiv,'prev')[0];


function getByClass(oP,sClass){

    if(oP.getElementsByClassName){        
        return oP.getElementsByClassName(sClass);    
    }else{
        var aResult=[];
        var aEle=oP.getElementsByTagName('*');
       
        for(var i=0;i<aEle.length;i++){
            /*将每个className拆分*/
            var arr=aEle[i].className.split(/\s+/);
            for(var j=0;j<arr.length;j++){
                /*判断拆分后的数组中有没有满足的class*/
                if(arr[j]==sClass){
                    aResult.push(aEle[i]);
                }
            }
        }
        return aResult;
    }

    
}


function hasClass(obj, cls) {
    return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}

function addClass(obj, cls) {
    if (!this.hasClass(obj, cls)) obj.className += " " + cls;
}

function removeClass(obj, cls) {
    if (hasClass(obj, cls)) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        obj.className = obj.className.replace(reg, ' ');
    }
}